package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.DDishCategories;
import com.ruoyi.system.service.IDDishCategoriesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 菜品类别Controller
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/categories")
public class DDishCategoriesController extends BaseController
{
    @Autowired
    private IDDishCategoriesService dDishCategoriesService;

    /**
     * 查询菜品类别列表
     */
    @RequiresPermissions("system:categories:list")
    @GetMapping("/list")
    public TableDataInfo list(DDishCategories dDishCategories)
    {
        startPage();
        List<DDishCategories> list = dDishCategoriesService.selectDDishCategoriesList(dDishCategories);
        return getDataTable(list);
    }

    /**
     * 导出菜品类别列表
     */
    @RequiresPermissions("system:categories:export")
    @Log(title = "菜品类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DDishCategories dDishCategories)
    {
        List<DDishCategories> list = dDishCategoriesService.selectDDishCategoriesList(dDishCategories);
        ExcelUtil<DDishCategories> util = new ExcelUtil<DDishCategories>(DDishCategories.class);
        util.exportExcel(response, list, "菜品类别数据");
    }

    /**
     * 获取菜品类别详细信息
     */
    @RequiresPermissions("system:categories:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dDishCategoriesService.selectDDishCategoriesById(id));
    }

    /**
     * 新增菜品类别
     */
    @RequiresPermissions("system:categories:add")
    @Log(title = "菜品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DDishCategories dDishCategories)
    {
        return toAjax(dDishCategoriesService.insertDDishCategories(dDishCategories));
    }

    /**
     * 修改菜品类别
     */
    @RequiresPermissions("system:categories:edit")
    @Log(title = "菜品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DDishCategories dDishCategories)
    {
        return toAjax(dDishCategoriesService.updateDDishCategories(dDishCategories));
    }

    /**
     * 删除菜品类别
     */
    @RequiresPermissions("system:categories:remove")
    @Log(title = "菜品类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dDishCategoriesService.deleteDDishCategoriesByIds(ids));
    }
}
